package cn.glutnn.service.impl;

import cn.glutnn.entity.Result;
import cn.glutnn.utils.ThreadLocalUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.glutnn.mapper.FinanceMapper;
import cn.glutnn.entity.Finance;
import cn.glutnn.service.FinanceService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (Finance)表服务实现类
 *
 * @author makejava
 * @since 2024-10-30 11:33:07
 */
@Service("financeService")
public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> implements FinanceService {

    @Override
    public Result editById(Finance finance) {
        finance.setUpdateTime(new Date());
        boolean b = update(finance, new UpdateWrapper<Finance>().eq("finance_id", finance.getFinanceId()));

        if (!b) {
            return Result.error("修改失败");
        }
        return Result.success();
    }

    @Override
    public Result<Page<Finance>> selectByBankIdAndUserName( String realName, Integer pageNum) {
        Map map = ThreadLocalUtil.get();
        Page<Finance> page = page(new Page<Finance>(pageNum, 10), new QueryWrapper<Finance>().eq("bank_id", map.get("bankId")).like("real_name", realName));
        return Result.success(page);



    }

    @Override
    public Result<Page<Finance>> selectByBankId(Integer pageNum, Integer pageSize) {
        Map map = ThreadLocalUtil.get();
        Page<Finance> page = page(new Page<Finance>(pageNum, pageSize), new LambdaQueryWrapper<Finance>().eq(Finance::getBankId, map.get("bankId")));


        return Result.success(page);
    }

    @Override
    public Result<Finance> selectByFinanceId(Integer financeId) {
        Finance one = getOne(new LambdaQueryWrapper<Finance>().eq(Finance::getFinanceId, financeId));
        return Result.success(one);
    }
}

